#ifndef TB_PREFIX_ABORT_H
#define TB_PREFIX_ABORT_H

#include "config.h"
#include "trace.h"
#include "assembler.h"

#if (defined(TB_ARCH_x86) || defined(TB_ARCH_x64))                             \
    && (!defined(TB_CONFIG_EXCEPTION_ENABLE) || defined(TB_CONFIG_OS_WINDOWS))
#if defined(TB_ASSEMBLER_IS_MASM) && !defined(TB_ARCH_x64)
//#       define tb_abort_done()                          do { __tb_asm__ { ud2
//} } while (0)
#define tb_abort_done()                                                        \
    do {                                                                       \
        __tb_asm__ { int 3 }                                                   \
    } while (0)
#elif defined(TB_ASSEMBLER_IS_GAS)
//#       define tb_abort_done()                          do { __tb_asm__
//__tb_volatile__ ("ud2"); } while (0)
#define tb_abort_done()                                                        \
    do {                                                                       \
        __tb_asm__ __tb_volatile__("int3");                                    \
    } while (0)
#endif
#endif

#ifndef tb_abort_done
#define tb_abort_done()                                                        \
    do {                                                                       \
        *((__tb_volatile__ tb_int_t *)0) = 0;                                  \
    } while (0)
#endif

// abort
#define tb_abort()                                                             \
    do {                                                                       \
        tb_trace_e("abort");                                                   \
        tb_abort_done();                                                       \
    } while (0)

#endif // !TB_PREFIX_ABORT_H
